<?php

/* @var $this yii\web\View */

$this->title = '玩客快栈';
?>
<div class="site-index">
    <?php echo $this->render('/public/top'); ?>
    <div class="col-lg-6" style="float: left; width: 100%; margin-top: 10px;">
        <div style="float:left;width: 20%">
            <img src="/images/pig/p<?php echo $userPetRow->pet->style?>.svg" width="180" class="pig-bg<?php echo $userPetRow->pet->getPetBack()?>">
        </div>
        <div style="float: left; padding-left: 10px">
            <p><?php echo (int) $userPetRow->pet->algebra?> 代 · <?php echo $userPetRow->pet->height?> kg</p>
            <p>成长: <?php echo $userPetRow->pet->grow?></p>
            <p>掘金：<?php echo $userPetRow->pet->nuggets?></p>
            <span data-v-59eaeb2c="">每投喂 1wkc 体重增长 <?php echo bcdiv($userPetRow->pet->nuggets, 1, 3)?>kg</span><br><br>
            <p>挂卖中</p>
            <p>
                <input type="text" name="amount" id="amount" style="width: 50px" value="0">
                <input type="hidden" name="pid" id="pid" value="<?php echo Yii::$app->request->get('pid')?>">
                <a href="javascript:void(0)" class="btn btn-info btn-small feed-pet">喂 食</a>
            </p>
            <p style="background-color：#dadada" id="showFeedMsg"></p>
        </div>
    </div>
    <div class="tabbable"> <!-- Only required for left/right tabs -->
        <ul class="nav nav-tabs">
            <li class="active"><a href="#tab1" data-toggle="tab">简介</a></li>
            <li><a href="#tab2" data-toggle="tab">喂养记录</a></li>
            <li><a href="#tab3" data-toggle="tab">掘金记录</a></li>
        </ul>
        <div class="tab-content">
            <div class="tab-pane active" id="tab1">
                <p>
                    <?php echo date('Y-m-d H:i:s', $userPetRow->pet->created_at)?>诞生
                </p>
                <p>
                    出生时获得：掘金：<?php echo $userPetRow->pet->birth_nuggets?> 成长：<?php echo $userPetRow->pet->birth_grow?>
                </p>
            </div>
            <div class="tab-pane" id="tab2">
                <p>您可以通过喂食得到属性的提升，获取更多的掘金收益</p>
                <table class="table table-striped">
                    <tr>
                        <th>喂食时间</th>
                        <th>体重</th>
                        <th>喂食数</th>
                        <th>掘金/成长</th>
                    </tr>
                    <?php if(!empty($historyFeedList)):?>
                    <?php foreach ($historyFeedList as $item):?>
                    <tr>
                        <td><?php echo date('Y-m-d H:i:s', $item->created_at)?></td>
                        <td><?php echo $item->height?></td>
                        <td><?php echo $item->amount?></td>
                        <td><?php echo $item->grow.'/'.$item->nuggets?></td>
                    </tr>
                    <?php endforeach;?>
                    <?php endif;?>
                </table>
            </div>
            <div class="tab-pane" id="tab3">
                <p>暂无</p>
            </div>
        </div>
    </div>
<!--    <div style="border-top: 1px solid #dadada;padding: 10px 10px">-->
<!--        <a href="#" class="btn">购买</a>-->
<!--    </div>-->
</div>
<script type="text/javascript">
    var token = '<?php echo Yii::$app->getRequest()->getCsrfToken(); ?>';
    $(document).ready(function () {
        $('.feed-pet').click(function () {
            var amount = $('#amount').val();
            var pid = $('#pid').val();
            if (amount <= 0) {
                alert('喂食金额必须大于0');
                return false;
            }
            $.post('/feed/add', {_csrf: token, amount: amount, pid : pid}, function (data) {
                var html = '';
                if (data.code == 10000) {
                    html = "<h4>喂食成功</h4><br>";
                    if (data.data.nuggets > 0) {
                        html += '掘金增加'+data.data.nuggets+'，';
                    }
                    if (data.data.grow > 0) {
                        html += '成长增加'+data.data.grow+'，';
                    }
                    html += '体重增加'+data.data.height;
                    $('#showFeedMsg').html(html);
                }
                return false;
            });
        });
    });
</script>
